// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   ChartPanel.java

package com.java4less.rchart.android;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import com.java4less.rchart.Chart;
import com.java4less.rchart.ChartListener;
import com.java4less.rchart.gc.ChartGraphics;
import com.java4less.rchart.gc.GraphicsProvider;

public class ChartPanel extends View
	implements ChartListener, android.view.View.OnClickListener, android.view.View.OnTouchListener
{

	public static String TAG = "J4LChart";
	private Chart chart;

	public ChartPanel(Context context)
	{
		super(context);
		chart = null;
		setClickable(true);
		setOnTouchListener(this);
	}

	public Chart getChart()
	{
		return chart;
	}

	public void setChart(Chart c)
	{
		if (chart != null)
			chart.removeChartListener(this);
		chart = c;
		chart.addChartListener(this);
	}

	protected void onSizeChanged(int w, int h, int oldw, int oldh)
	{
		chart.setWidth(w);
		chart.setHeight(h);
	}

	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
	{
		setMeasuredDimension(chart.getWidth(), chart.getHeight());
	}

	public void onDraw(Canvas g)
	{
		super.onDraw(g);
		if (g == null)
			return;
		try
		{
			ChartGraphics g2 = GraphicsProvider.getGraphics(g);
			chart.doubleBuffering = false;
			chart.paint(g2);
			g2.dispose();
		}
		catch (Exception err)
		{
			Log.e("j4LChart", (new StringBuilder()).append("j4lChart onDraw exception ").append(err.getMessage()).toString(), err);
		}
		return;
	}

	public void paintUserExit(Chart chart1, ChartGraphics chartgraphics)
	{
	}

	public void chartEvent(Chart c, int type)
	{
		if (type == 4)
			invalidate();
		if (type == 1)
			((Activity)super.getContext()).runOnUiThread(new Runnable() {

				final ChartPanel this$0;

				public void run()
				{
					invalidate();
				}

			
			{
				this$0 = ChartPanel.this;
				super();
			}
			});
	}

	public void onClick(View v)
	{
		if (chart == null);
	}

	public boolean onTouch(View v, MotionEvent e)
	{
		if (e.getAction() == 0 && chart != null)
		{
			float x = e.getX();
			float y = e.getY();
			chart.mouseMoved((int)x, (int)y);
			chart.mouseClick();
			return true;
		} else
		{
			return false;
		}
	}

}
